import pandas as pd

# df = pd.DataFrame([
#     [1,1,1,1],
#     [2,2,2,2],
#     [3,3,3,3]
# ], columns=['col1', 'col2', 'col3', 'col4'])

# print(df)

# print(df.mean(axis=1))

# print(df.drop('col4', axis=1))

peoples = pd.read_excel('pandas7.xlsx', index_col='ID')

column_names = ['小测1', '小测2', '小测3']

# 对每一行中的每一列进行求和操作
row_sum = peoples[column_names].sum(axis=1)
# 对每一行中的每一列进行求平均操作
row_mean = peoples[column_names].mean(axis=1)

total = '总分'
average = '平均分'

peoples[total] = row_sum
peoples[average] = row_mean

column_names += [total, average]

# axis默认值为0，对每一列中的每一行进行求平均操作
col_mean = peoples[column_names].mean()
col_mean['名称'] = 'Summary'
# append方法添加新的一行，ignore_index为True表示忽略index
peoples = peoples.append(col_mean, ignore_index=True)

print(peoples)
